﻿using System;
using System.Collections.Generic;

namespace EasySL.Core
{
    public class TaskList : List<Task>
    {
        public event Action End;
        public event Action Begin;

        public bool HasNext
        {
            get
            {
                return (this.Count > 0 &&
                        this._curTaskIndex < this.Count - 1);
            }
        }

        public void Next()
        {
            if (this.HasNext)
            {
                this._curTaskIndex++;
                Task proc = this[this._curTaskIndex];
                proc.Start(this);
            }
            else
            {
                if (this.End != null)
                {
                    this.End();
                }
            }
        }

        public void Start()
        {
            if (this.Begin != null)
                this.Begin();

            this._curTaskIndex = -1;

            this.Next();
        }

        private int _curTaskIndex = -1;
    }
}
